package com.sss.myspringsecurity.config.securityconfig.filter;

import com.alibaba.fastjson.JSON;
import com.sss.myspringsecurity.util.ResponseDataEnum;
import com.sss.myspringsecurity.util.Result;
import com.sss.myspringsecurity.util.ServletUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 权限不足 处理类
 * @author sss
 * @date 2020-02-09 19:46
 **/
@Slf4j
@Component
public class CustomerRestAccessDeniedHandler implements AccessDeniedHandler {
    @Override
    public void handle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, AccessDeniedException e) throws IOException, ServletException {
        ServletUtils.renderString(httpServletResponse, JSON.toJSONString(Result.fail(ResponseDataEnum.NOTAUTHOR)));
    }
}
